// useCesiumClick.config
import * as Cesium from 'cesium';

export function useCesiumClick(viewer, callback) {
  const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

  handler.setInputAction(function (click) {
    viewer._selectedEntity = []; //去除左击之后出现选中的绿框
    viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK); //取消双击的事件
    const pickedObject = viewer.scene.pick(click.position);
    if (Cesium.defined(pickedObject)) {
      if (pickedObject.id._position || pickedObject.id.polygon) {
        callback(pickedObject, click);
      }
    }
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  handler.setInputAction(function (movement) {
    const pickedObject = viewer.scene.pick(movement.endPosition);
    if (pickedObject == undefined || !pickedObject.id._description) {
      viewer._container.style.cursor = 'default';
    } else {
      viewer._container.style.cursor = 'pointer';
    }
  }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
